package com.example.demo.Mapper;

import com.example.demo.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {

    //通过id查询图书
    @Select("select * from book_info where id = #{bookId}")
     BookInfo queryBookById(Integer bookId);

    //插入图书
    @Insert("insert into book_info (book_name, author, count, price, publish, `status`) " +
            "values (#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    Integer insertBook(BookInfo bookInfo);

    //查询总记录数
    @Select("select count(1) from book_info where status != 0")
    Integer count();//得到总记录数

    //查询图书信息
    @Select("select * from book_info where status !=0 order by id limit #{offset}, #{limit}")
    List<BookInfo> queryBookByPage(Integer offset, Integer limit);

    //更新图书,用xml的方式 注解和xml的方式可以混用
    Integer updateBook(BookInfo bookInfo);

    @Select("select * from book_info")
    List<BookInfo> selectAll();

    void batchDelete(List<Integer> ids);
}
